﻿using System.Web.Mvc;
using SharePointEditor.BusinessDefinitions.Classes;
using SharePointEditor.Web.Helpers;
using SharePointEditor.Web.Models;
using SharePointEditor.Web.Extensions;

namespace SharePointEditor.Web.Controllers
{
    [HandleError]
    public class AjaxController : BaseController
    {
        [JsonFilter(Param = "list", JsonDataType = typeof(SPEList))]
        public ActionResult LoadListItems(SPEList list)
        {
            var listItemsModel = new ListItemsModel
                                     {
                                         ListItems = list.Items
                                     };
            return Json(new {partialhtml = this.RenderPartialViewToString("ViewListItemsControl", listItemsModel)});
        }

        [JsonFilter(Param = "listItem", JsonDataType = typeof(SPEListItem))]
        public ActionResult LoadListItemProperties(SPEListItem listItem)
        {
            var listItemPropertiesModel = new ListItemPropertiesModel
            {
                Title = "Test"
            };
            return Json(new { partialhtml = this.RenderPartialViewToString("ViewListItemPropertiesControl", listItemPropertiesModel) });
        }
    }
}
